<pre class="docs-method-signature"><code>paper.fitToContent([opt])</code></pre>
<p>Expand or shrink the paper to fit the content inside it. The method returns the area (<code>g.Rect</code>) of the paper after fitting in local coordinates.</p>

<p>The function accepts an object with additional settings (all optional):</p>

<ul>
  <li><code>opt.gridWidth</code> and <code>opt.gridHeight</code> – snap the resulting width and height of the paper to a grid defined by these dimensions.</li>
  <li><code>opt.padding</code> – additional padding around the resulting paper. It may be specified as a number, in which case it represents the padding width on all sides of the paper. It may be an object of the form <code>{ top?: [number], right?: [number], bottom?: [number], left?: [number], vertical?: [number], horizontal?: [number] }</code>.</li>
  <li><code>opt.allowNewOrigin</code> – should the origin of the resulting paper be adjusted to match the origin of the paper content? In addition to no value being set, three values are recognized by this option: <code>'positive'</code>,&nbsp;<code>'negative'</code>,&nbsp;<code>'any'</code>.
    <ul>
      <li>By default, the method only recognizes the content at positive coordinates and puts the origin of resulting paper at the original point (0,0).</li>
      <li><code>'positive'</code> – the method only recognizes the content at positive coordinates and puts the origin of resulting paper at the origin of the content. (Still, if the content starts at negative coordinates in an axis, the resulting paper's origin will be assigned <code>0</code> in that axis.)</li>
      <li><code>'negative'</code> – the method only recognizes the content at negative coordinates and puts the origin of resulting paper at the origin of the content. (However, if the content starts at positive coordinates in an axis, the resulting paper's origin will be assigned <code>0</code> in that axis.)</li>
      <li><code>'any'</code> – the method recognizes all of paper content. The origin of the resulting paper will be at the origin of the content.</li>
    </ul>
  </li>
  <li><code>opt.minWidth</code> and <code>opt.minHeight</code> – define the minimum width and height of the resulting paper after fitting it to content.</li>
  <li><code>opt.maxWidth</code> and <code>opt.maxHeight</code> – define the maximum width and height of the resulting paper.
  after fitting it to content.</li>
  <li><code>opt.useModelGeometry</code> – should paper content area be calculated from cell models instead of views? Default is <code>false</code>. See the documentation of the <code>paper.getContentArea</code> <a href="#dia.Paper.prototype.getContentArea">function</a> for more details.</li>
  <li><code>opt.contentArea</code> – an object of the form <code>{ x: [number], y: [number], width: [number], height: [number] }</code> is the area representing the content bounding box in the local coordinate system that paper should be fitted to. By default <code>opt.contentArea</code> is <code>paper.getContentArea(opt)</code>.</li>
</ul>

<p>You can try many of these options interactively in the <a href="http://jointjs.com/demos/paper">paper demo</a>.</p>

<p>This method might internally trigger the <code>&quot;resize&quot;</code> and <code>&quot;translate&quot;</code> events. These can be handled by listening on the paper object (<code>paper.on('resize', myHandler)</code>).</p>


<pre class="docs-method-signature"><code>paper.fitToContent([gridWidth, gridHeight, padding, opt])</code></pre>
<p><i>Depracated usage. All parameters are expected to be passed inside the <code>opt</code> object.</i></p>
